<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            height: 100%;
            font-family: "宋体", sans-serif;
            background: #302a34;
        }
        h1{
            color: #dfd1b5;
            text-align: center;
            margin-top: 20px;
        }
        body>h1>a{
            text-decoration:none;
            color: #dfd1b5;
        }
        form{
            color: #dfd1b5;
            font-size: 25px;
            text-align: center;
            margin-top: 100px;
        }
        input,th{
            font-size: 20px;
            height: 35px;
            font-family: "宋体", sans-serif;
            background-color: #302a34;
            color: #dfd1b5;
        }
        input{
            -webkit-box-shadow: 0 0 0px 1000px #302a34 inset;
            -webkit-text-fill-color: #dfd1b5;
        }
        th{
            background-color: #302a34;
            color: #dfd1b5;
        }
        table{
            border-radius: 4px;
            margin: 0 auto;
        }

        footer{
            /*固定定位*/
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
        }
        footer>div{
            padding: 50px 0;
        }
        footer>div>div{
            text-align: center;
            line-height: 1.8;
            font-size: 12px;
            color: #f6f5f5;
            font-weight: 200;
        }
    </style>
</head>
<body>
<h1><a href="/index.html">烤天下烧烤加盟</a></h1>
<hr>
<form action="" class="container">
    <table bgcolor="#a20d1f" class="container">
        <caption>用户注册</caption>
        <tr bgcolor="#a20d1f">
            <th>用户名:</th>
            <td><input type="text" name="username" placeholder="请输入用户名" @blur="check()"></td>
        </tr>
        <tr bgcolor="#a20d1f">
            <th>密码:</th>
            <td><input type="password" name="password" placeholder="请输入密码"></td>
        </tr>
        <!--<tr bgcolor="#a20d1f">
            <th>确认密码:</th>
            <td><input type="password" name="password" placeholder="请确认密码"></td>
        </tr>-->
        <tr bgcolor="#a20d1f">
            <th>昵称:</th>
            <td><input type="text" name="nick" placeholder="昵称"></td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" value="注册" @click="reg()"></td>
        </tr>
    </table>
</form>
<footer style="background-color: #302a34">
    <div>
        <div>©AUI 素材网 京ICP备15006025号-1</div>
        <div>
            "Copyright © 2012-2016 www.a-ui.cn"
            <span>地址：北京市海淀区北三环西路43号中航广场6层</span>
        </div>
    </div>
</footer>
<!--引入vue和axios-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"form",
        data:{
            info:""
        },
        methods:{
            check:function () {
                let data = new FormData(document.querySelector("form"));
                axios.post("/check",data).then(function (response) {
                    v.info = response.data==1?"用户名可用!":"用户名已存在!"
                })
            },
            reg:function () {
                let data = new FormData(document.querySelector("form"));
                axios.post("/reg",data).then(function (response) {
                    if (response.data==1){
                        alert("注册成功!");
                        location.href="/";//回到首页
                    }else{
                        alert("用户名已存在!");
                    }
                })

            }
        }
    })
</script>
</body>
</html>